package com.atguigu.srb.oss.controller;

import com.atguigu.common.result.R;

import com.atguigu.srb.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@Api(tags = "阿里云文件管理")
//@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/api/oss/file")
public class ApiOssController {
    @Resource
    private OssService ossService;

    @ApiOperation("图片上传")
    @PostMapping("/uploadImage")
    public R uploadImage(@RequestParam("file") MultipartFile file, String module){
      String url =  ossService.uploadImage(file,module);
      return R.ok().data("url",url);
    }

    @ApiOperation("删除OSS文件")
    @DeleteMapping("/deleteImage")
    public R removeImage(String url) {
        ossService.deleteImage(url);
        return R.ok().message("删除成功");
    }

}
